﻿using System.Web;
using System.Web.Mvc;
using System.IO;
using System;
namespace CRMSystemV2.MVCWeb
{
    public static class WebExtension
    {
        /// <summary>
        /// 利用dwz的ajaxDone时输出干净的json,而不带xml的格式
        /// </summary>
        /// <param name="json"></param>
        public static void Write(this HttpResponseBase response, ajaxDone json)
        {
            response.ContentEncoding = System.Text.Encoding.UTF8;
            response.Write(json.SerializeObject());
            response.End();
        }
        /// <summary>
        /// 序列化对象
        /// </summary>
        /// <param name="json"></param>
        /// <returns></returns>
        private static string SerializeObject(this ajaxDone json)
        {
            return CRMSystemV2.Common.JsonHelper.SerializeObject(json);
        }
        /// <summary>
        /// 反序列化
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="jsonData"></param>
        /// <returns></returns>
        public static ResultJson DeserializeObject(this string json)
        {
            return CRMSystemV2.Common.JsonHelper.DeserializeObject<ResultJson>(json);
        }       
    }
    /// <summary>
    /// dwz框架返回的json格式
    /// </summary>
    public class ajaxDone
    {
        public int statusCode { get; set; }
        public string message { get; set; }
        /// <summary>
        /// Index页面中的rel值
        /// </summary>
        public string navTabId { get; set; }
        public string rel { get; set; }
        public string callbackType { get; set; }
        public string forwardUrl { get; set; }
        public string confirmMsg { get; set; }
    }
    /// <summary>
    /// 数据库返回的json格式
    /// </summary>
    [Serializable]
    public class ResultJson
    {
        public int status { get; set; }
        public string message { get; set; }
    }
}